package com.system.manager.modules.development.controller;


import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.Result;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.development.entity.DeveContract;
import com.system.manager.modules.development.entity.DevePurchase;
import com.system.manager.modules.development.service.IDeveContractService;
import com.system.manager.modules.development.service.impl.DeveClassServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yxp
 * @since 2021-11-17
 */
@Api(tags = "合同备案API")
@RestController
@RequestMapping("/development/deve-contract/")
public class DeveContractController {
    @Autowired
    private IDeveContractService deveContractService;

    @ApiOperation("新建合同备案")
    @PreAuthorize(SubjectType.PROJECT_LEADER)
    @PostMapping("insert/contract")
    public Result insertContract(@RequestBody DeveContract deveContract){
        try {
            deveContractService.insertContract(deveContract);
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }

    @ApiOperation("删除合同备案")
    @PreAuthorize(SubjectType.PROJECT_LEADER)
    @GetMapping("delete/contract")
    public Result deleteContract(Integer id){
        try{
            deveContractService.deleteContract(id);
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }
    @ApiOperation("查找合同")
    @PreAuthorize(SubjectType.PROJECT_LEADER)
    @GetMapping("select/contract")
    public Result selectAllContract(@RequestParam(name = "page", required = false, defaultValue = "1")Integer page,
                                  @RequestParam(name = "limit", required = false, defaultValue = "10")Integer size,
                                  @RequestParam(name = "id",required = false) Integer id){
        try{
            Result result =  deveContractService.selectAllContract(page,size,id);
            return result;
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }



}
